package com.cykj.service.Impl;

import com.cykj.dto.ResponseDto;
import com.cykj.mapper.TypeMapper;
import com.cykj.pojo.PsAdmin;
import com.cykj.pojo.PsTopic;
import com.cykj.pojo.PsType;
import com.cykj.service.TypeService;
import com.cykj.vo.PsTopicVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @BelongsProject: Psychology
 * @BelongsPackage: com.cykj.service.Impl
 * @Author: 小林
 * @CreateTime: 2025-02-04 20:38
 * @Description: 领域表service层  (增删改查)
 * @Version: 1.0
 */
@Service
public class TypeServiceImpl implements TypeService {
    @Autowired
    private TypeMapper typeMapper;

    /**
     * 根据领域获取id
     * @param vo
     * @return
     */
    @Override
    public ResponseDto getTopicsByTypeId(PsTopicVo vo) {
         List<PsTopic> psTopics = typeMapper.selectTopicsByTypeId(vo);
        return psTopics != null ? ResponseDto.success(psTopics) : ResponseDto.error("查询有误！");
    }

    /**
     * 获取所有领域
     * @return
     */
    @Override
    public ResponseDto getAllTypes() {
        List<PsType> psTypes = typeMapper.selectAllTypes();
        return psTypes != null ? ResponseDto.success(psTypes) : ResponseDto.error("查询有误！");
    }

    /**
     * 删除对应题目id的所有东西
     * @param vo
     * @return
     */
    @Override
    public ResponseDto deleteTopicByTopicId(PsTopicVo vo) {
        int i = typeMapper.deleteTopicByTopicId(vo);
        if (i > 0) {
            return ResponseDto.success("删除成功！");
        }
        return ResponseDto.error("删除失败");
    }

    /**
     * 插入领域的题目
     * @param vo
     * @return
     */
    @Override
    public ResponseDto insertTopic(PsTopicVo vo) {
        int i = typeMapper.insertTopic(vo);
        if (i > 0){
            return ResponseDto.success("新增成功！");
        }
        return ResponseDto.error("新增失败！");
    }

    /**
     * 修改题目
     * @param vo
     * @return
     */
    @Override
    public ResponseDto updateTopic(PsTopicVo vo) {
        int i = typeMapper.updateTopic(vo);
        if (i > 0){
            return ResponseDto.success("修改成功！");
        }
        return ResponseDto.error("修改失败！");
    }

    /**
     * 获取全部
     * @param pageNum
     * @param pageSize
     * @return
     */
    @Override
    public ResponseDto getAll(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
         List<PsTopic> all = typeMapper.getAll();
        PageInfo<PsTopic> pageInfo = new PageInfo<>(all);
        return ResponseDto.success(pageInfo);
    }
}

